import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/lao',
    name: 'lao',
    component: ()=>import("../views/lao.vue")
  },
  {
    path: '/login',
    name: 'login',
    component: ()=>import("../views/login.vue")
  },
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/user',
    name: 'user',
    component: ()=>import("../views/user/index.vue"),
    children:[
      {
        path: '/tab',
        name: 'tab',
        component: ()=>import("../views/user/tab.vue")
      },
      {
        path: '/ji',
        name: 'ji',
        component: ()=>import("../views/user/ji.vue")
      },
      {
        path: '/hou',
        name: 'hou',
        component: ()=>import("../views/user/hou.vue")
      },
    ]
  },
  
  
]

const router = new VueRouter({
  routes
})
// router.beforeEach((to, from, next)=>{
//   if (this.$store.state.user("token") ){
//     next();
//   } else {
//     if(to.path !="/lao"){
//       next()
//     }else{
//       next("/login")
//     }
//   }
// })
//在router.js中配置的路由下方放入（为了防止router中push方法的bug出现）：
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  		if (typeof (location) == "string") {
 			var Separator = "&";
 			if (location.indexOf('?') == -1) {
   				Separator = '?';
 			}
 			location = location + Separator + "random=" + Math.random();
  		}
  		return routerPush.call(this, location).catch(error => error)
}


export default router
